<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <link href="/after/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
    <link href="/after/css/font-awesome.min.css?v=4.3.0" rel="stylesheet">
    <link href="/after/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="/after/css/animate.min.css" rel="stylesheet">
    <link href="/after/css/style.min.css?v=3.0.0" rel="stylesheet">

    <link href="/after/js/laypage/skin/laypage.css" rel="stylesheet">
    <!--引用vue的js-->
    <script src="/after/js/vue/vue.min.js"></script>
    <!--分页插件-->
    <script src="/after/js/laypage/laypage.js" charset="utf-8"></script>
    <script src="/after/js/layer/layer.js" charset="utf-8"></script>


    <script src="/after/js/jquery-2.1.1.min.js" type="text/javascript"></script>
    <script src="/after/js/bootstrap.min.js?v=3.4.0" type="text/javascript"></script>
    <script type="text/javascript" src="/after/js/Globals.js"></script>
    <script type="text/javascript" src="/after/js/websocket.js"></script>
    <script type="text/javascript" src="/after/js/vue/vue.min.js"></script>
    <script src="/after/js/layer/layer.js" charset="utf-8"></script>
</head>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <br>
    <br>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <form class="form-inline bg-danger" role="form">
                    查询条件：
                    <div class="form-group">
                        <label class="sr-only" for="name">优惠券名称</label>
                        <input type="text" class="form-control" id="name" placeholder="优惠券名称">
                    </div>
                    <button type="button" id="findUser" class="btn btn-success">查询优惠券</button>
                    <button type="button" id="addUserBtn" class="btn btn-danger">增加优惠券</button>
                </form>
                <div class="ibox-content">
                    <table class="table table-striped table-bordered table-hover " id="editable">
                        <thead>
                        <tr class="success">
                            <td>名称</td>
                            <td>金额</td>
                            <td>满减条件</td>
                            <td>开始时间</td>
                            <td>结束时间</td>
                            <td>总数</td>
                            <td>余数</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="active" v-for="(item,index) in result">
                            <td>{{item.name}}</td>
                            <td>{{item.money}}</td>
                            <td>{{item.conditio}}</td>
                            <td>{{new Date(item.startTime).toLocaleString()}}</td>
                            <td>{{new Date(item.endTime).toLocaleString()}}</td>
                            <td>{{item.coun}}</td>
                            <td>{{item.remain}}</td>
                            <td><a href="#" @click="editEvent(item.id)">编辑</a> <a href="#" @click="delEvent(item.id)">删除</a></td>
                        </tr>
                        </tbody>
                    </table>
                    <div id="pagenav"></div>
                </div>
            </div>
        </div>
    </div>
</div>






<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });


    //查询用户数据
    var getUserPageList = function (curr) {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/czgDiscount/queryByPage.do",
            data: {
                pageNum: curr || 1,
                pageSize: 5,
                name: $("#name").val()
            },
            success: function (msg) {
                app.result = msg.page;
                laypage({
                    cont: 'pagenav', //容器。值支持id名、原生dom对象，jquery对象,
                    pages: msg.totalPage, //总页数
                    skin: '#FFFFFF',
                    first: '首页',
                    last: '尾页',
                    curr: curr || 1, //当前页
                    jump: function (obj, first) { //触发分页后的回调
                        if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                            getUserPageList(obj.curr);
                        }
                    }
                });
            }
        });
    }

    getUserPageList();

    //查询用户事件

    $('#findUser').on('click', function () {
        getUserPageList();
    });


    //编辑事件

    var editEvent = function (id) {
        layer.open({
            type: 2,
            title: '编辑优惠券',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['1100px', '700px'],
           // content: '/czgDiscount/editp.do?id=' + id,
            content:'CzgEditDiscount.ftl?id='+id,
            end: function () {
                getUserPageList();
            }
        });
    }

    //增加事件

    $('#addUserBtn').on('click', function () {
        layer.open({
            type: 2,
            title: '添加优惠券',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['1100px', '700px'],
            content: '/backstage/CzgAddDiscount.ftl',
            end: function () {
                getUserPageList();
            }
        });

    });


    //删除事件
    var delEvent = function (id) {
        //询问框
        layer.confirm('您确定要删除么？', {
            btn: ['是', '否']
            //按钮
        }, function () {
            //是
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "/czgDiscount/del.do",
                data: {
                    id: id
                },
                success: function (msg) {
                    getUserPageList();
                    layer.msg('删除成功' + id, {icon: 1});
                }
            });

        }, function () {
            //否

        });
    }


</script>


</body>
</html>